﻿using System;
using System.Drawing;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;

namespace ExchangeRateService.ViewModel
{
	/// <summary>
    /// Represents an actionable item displayed by a View.
    /// </summary>
    public class CommandViewModel : AbstractViewModel
    {
        public CommandViewModel(String displayName, ICommand command)
        {
            if (command == null)
                throw new ArgumentNullException("command");

            base.DisplayName = displayName;
            this.Command = command;
        }
        
        public CommandViewModel(String displayName, ICommand command, Bitmap bitmap)
        	: this(displayName, command, LoadBitmap(bitmap))
        {
            TextVisibility = Visibility.Visible;
        }

        public CommandViewModel(String displayName, ICommand command, ImageSource image)
        	: this(displayName, command)
        {
            SmallImageSource = image;
        }

        public ICommand Command { get; private set; }
        
        public virtual String ToolTipTitle { get; protected set; }
        public virtual String ToolTipDescription { get; protected set; }
        
        public virtual ImageSource SmallImageSource { get; protected set; }
        public virtual ImageSource LargeImageSource { get; protected set; }
        
        public virtual Visibility TextVisibility { get; set; }
        
        static System.Windows.Media.Imaging.BitmapSource LoadBitmap(Bitmap source)
        {
            return System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(source.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty,
                System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
        }
    }
}
